﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Text;
public partial class admin_志愿者管理_志愿者管理_Detail : BLL.BasePage_Admin
{
    User_Volunteer bll_User_Volunteer = new User_Volunteer();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblMsg.Text = "";
        if (!IsPostBack)
        {
            UIInit();
        }
    }

    private void UIInit()
    {
        Bind_RoleList();
        Bind_Detail();
    }

    private void Bind_RoleList()
    {
        BLL.PublicControlBind.Bind_DLL_RoleList(ddlRoleList);
        ddlRoleList.Items.RemoveAt(0);
    }

    private void Bind_Detail()
    {
        int id = QueryString_Int("id");
        Model.User_Volunteer m = bll_User_Volunteer.GetModel(id);
        ImgUploader1.ImageURL = "~/Images_Face/" + m.Img_Face;
        lblAge.Text = m.Age.ToString();
        lblArea.Text = m.Area;
        lblInsTime.Text = m.InsTime.ToString("yyyy年MM月dd日");
        lblMail.Text = m.Email;
        lblLogin.Text = Get_LoginInfo(m);
        lblName.Text = m.Nickname;
        lblPhoneNumber.Text = m.PhoneNumber;
        lblQQ.Text = m.QQ;
        lblSex.Text = m.Sex;
        lblSlogan.Text = m.Slogan;
        lblTimeSpan.Text = Convert.ToInt32((DateTime.Now - m.InsTime).TotalDays).ToString()+"天";
        ddlRoleList.SelectedValue = m.RoleId.ToString();
    }

    private string Get_LoginInfo(Model.User_Volunteer m)
    {
        string str = "自加入暖心义工以来，共登陆 " + m.LoginCount + " 次，最后登陆时间为：" + m.LastLoginTime.ToString() + " ， IP：" + m.LastIP + "。";
        return str;
    }
    protected void ddlRoleList_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = QueryString_Int("id");
        Model.User_Volunteer m = bll_User_Volunteer.GetModel(id);
        m.RoleId = Convert.ToInt32(ddlRoleList.SelectedValue);
        bll_User_Volunteer.Update(m);
        lblMsg.Text = "角色变更已保存";
        lblMsg.ForeColor = System.Drawing.Color.Green;
    }
}